package ch.unisi.inf.java.project.riskbami.model;


/**
 * GetArmiesCommand is an extension of GenericCommand.
 * Provide the implementation of a commands that is responsible to obtain
 * the armies for a turn.
 * 
 * @author minellir@lu.unisi.ch
 * @author babazadm@lu.unisi.ch
 */
public final class GetArmiesCommand extends GenericCommand
{
    private final Player player;
    private final Game game;
    
    /**
     * The contructor for the class GetArmiesCommand
     * 
     * @param game The actual game
     */
    public GetArmiesCommand(final Game game) {
        super(game);
        this.game = game;
        this.player = game.getCurrentPlayer();
    }

    /**
     * canExecute verify whether the GetArmiesCommand could be executed
     * 
     * @return boolean
     */
    public final boolean canExecute() {
        if(game.getTurnPhase() == 0) {
            return true;
        }
        else return false;
    }
    
    /**
     * execute is responsible to execute the given GetArmiesCommandw command.
     */
    public final void execute(){
        if(player.getPerTurnArmies() == -1){ // way to encode the first turn
            player.setFirstTurnArmies(game.getNumberOfPlayers());
        }
            
        if(!player.isInitialPlacing()){ 
            player.computePerTurnArmies();
            if(player.getPerTurnArmies() == 0){
                game.switchNextPhase();
            }
        }   
        game.switchNextPhase();
    }
}
